/** Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.*/
package com.truba.ohostouchgallery.slice;

import com.truba.ohostouchgallery.GalleryFileAbility;
import com.truba.ohostouchgallery.GalleryUrlAbility;
import com.truba.ohostouchgallery.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_btn_1).setClickedListener(this);
        findComponentById(ResourceTable.Id_btn_2).setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn_1:
                startAbility1();
                break;
            case ResourceTable.Id_btn_2:
                startAbility2();
                break;
            default:
                break;
        }
    }

    private void startAbility1() {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withBundleName(getBundleName())
                .withAbilityName(GalleryUrlAbility.class).build();
        intent.setOperation(operation);
        startAbility(intent);

    }

    private void startAbility2() {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
               // .withDeviceId("")
              /*  .withBundleName("com.example.ohostouchgallery")
                .withAbilityName("com.example.ohostouchgallery.GalleryFileAbility")*/
                .withBundleName(getBundleName())
                .withAbilityName(GalleryFileAbility.class.getName())
                .build();
        intent.setOperation(operation);
        startAbility(intent);
    }
}